<template>
    <div>
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>单位名称</label>
            </div>
            <div>
                <p>{{detailData.ProjectName}}</p>
            </div>
        </div>
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>物资名称</label>
            </div>
            <div>
                <p>{{detailData.GoodsName}}</p>
            </div>
        </div>
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>物资类型</label>
            </div>
            <div>
                <p>{{detailData.GoodsType}}</p>
            </div>
        </div>
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>编码</label>
            </div>
            <div>
                <p>{{detailData.GoodsCode}}</p>
            </div>
        </div>
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>数量</label>
            </div>
            <div>
                <p>{{detailData.GoodsNum}}</p>
            </div>
        </div>
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>单位</label>
            </div>
            <div>
                <p>{{detailData.GoodsUnit}}</p>
            </div>
        </div>
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>型号</label>
            </div>
            <div>
                <p>{{detailData.GoodsModel}}</p>
            </div>
        </div>
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>入库时间</label>
            </div>
            <div>
                <p>{{detailData.GoodsTime?detailData.GoodsTime.split(' ')[0]:''}}</p>
            </div>
        </div>
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>存放地址</label>
            </div>
            <div>
                <p>{{detailData.GoodsPlace}}</p>
            </div>
        </div>
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>有效期</label>
            </div>
            <div>
                <p>{{detailData.GoodsValidity?detailData.GoodsValidity.split(' ')[0]:''}}</p>
            </div>
        </div>
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>责任人</label>
            </div>
            <div>
                <p>{{detailData.GoodsDutyName}}</p>
            </div>
        </div>
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>联系方式</label>
            </div>
            <div>
                <p>{{detailData.GoodsDutyTel}}</p>
            </div>
        </div>
        <div class="form-item form-item-style2">
            <div class="label-title">
                <label>功能</label>
            </div>
            <div>
                <p class="textarea">{{detailData.GoodsFunction}}</p>
            </div>
        </div>
        <div class="cut-off-rule"></div>
        <div class="form-section">
            <h3>
                附件信息
            </h3>
            <div class="form-item form-item-style1"
                 v-for="(item,index) in detailData.Files"
                 :key="index"
                 @click="preview(item)">
                <div class="label-title label-title1">
                    <label>{{item.FileName}}</label>
                </div>
                <div class="right-section">
                    <span>预览</span>
                    <x-icon type="ios-arrow-right"
                            size="20"
                            class="icon-right"></x-icon>
                </div>
            </div>
        </div>
        <div class="cut-off-rule"></div>
        <div class="form-section">
            <h3>
                变更信息
            </h3>
            <router-link :to="{name:'changeRecordDetail',params:{detail:item}}"
                         class="form-item form-item-style1"
                         v-for="(item,index) in changeList"
                         :key="index">
                <div class="label-title label-title1">
                    <label>{{item.DetailName}}</label>
                </div>
                <div class="right-section">
                    <span>{{item.Detailway}}</span>
                    <x-icon type="ios-arrow-right"
                            size="20"
                            class="icon-right"></x-icon>
                </div>
            </router-link>
        </div>
        <div class="btns">
            <router-link :to="{name:'junkedRegister',params:{detail:detailData}}"
                         class="green width200">领用报废登记</router-link>
        </div>
        <myMenu ref="myMenu"></myMenu>
    </div>
</template>
<script>
import myMenu from '@/commonComponents/menu'
export default {
    name: 'goodsDetail',
    components: {
        myMenu
    },
    data () {
        return {
            regImg: /\.(png|jpg|PNG|JPG|jpeg|JPEG|gif|GIF)$/,
            userInfo: {},
            detailData: {},
            changeList: []
        }
    },
    created () {
        this.userInfo = JSON.parse(localStorage.getItem('userInfo')) || {}
        this.detailData = this.$route.params.detail
        this.getChangeList()
    },
    activated () {
        if (this.$refs.myMenu) this.$refs.myMenu.flag = false
        if (this.$route.params.detail) this.detailData = this.$route.params.detail
        this.getChangeList()
    },
    methods: {
        preview (filePath) {
            if (this.regImg.test(filePath)) {
                this.$router.push({
                    path: '/previewImg',
                    query: {
                        previewImg: filePath
                    }
                })
            } else {
                wx.miniProgram.navigateTo({
                    url: `/pages/openDocument/index?filePath=${filePath}`
                })
            }
        },
        getChangeList () {
            let params = {
                'allowPaging': true,
                'business': 'GetChangeList',
                'data': {
                    'GoodsId': this.detailData.ID
                },
                'pageIndex': 1,
                'pageSize': 20,
                'tokenId': '',
                'userId': this.userInfo.userid
            }
            this.$axiosAjax.getConfigJson(params).then((res) => {
                if (res.data.code === 0) {
                    this.changeList = res.data.data
                }
            }).catch(() => {

            }).finally(() => {
                this.$vux.loading.hide()
            })
        }
    }
}
</script>
<style scoped>
.btns a {
    display: block;
    height: 40px;
    line-height: 40px;
    text-align: center;
    background: #2269ff;
    border-radius: 20px;
    color: #fff;
    font-size: 14px;
}
.form-item .label-title label {
    max-width: 250px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
</style>
